/*
 * addon.h
 *
 *  Created on: 2010-1-7
 *      Author: gavinkwoe
 */

#ifndef ADDON_ENCODING_H_
#define ADDON_ENCODING_H_

#include "addon_features.h"
#include "addon_std.h"
#include "addon_objbase.h"

/*************************************************************************
* MACRO
*************************************************************************/

#define ADDON_ENCODING_UNKNOWN	(0)
#define	ADDON_ENCODING_ASCII	(1)
#define	ADDON_ENCODING_UTF8		(2)
#define	ADDON_ENCODING_UCS2		(3)
#define	ADDON_ENCODING_GB2312	(4)
#define	ADDON_ENCODING_GB12345	(5)
#define	ADDON_ENCODING_GBK		(6)
#define	ADDON_ENCODING_BIG5		(7)
#define ADDON_ENCODING_JIS		(8)
#define ADDON_ENCODING_TOTAL	(9)

#define ADDON_BIG_ENDIAN		(0)
#define ADDON_LITTLE_ENDIAN		(1)

/*************************************************************************
* INTERFACE
*************************************************************************/

ADDON_INTERFACE_( IAddonEncoding, 1, IObject )
{
	__INHERIT_FROM( IObject )

	ADDON_METHOD( Guess )		( ADDON_REF(IObject) thiz, IN unsigned char * buff, IN unsigned long buff_size,
									OUT unsigned long * enc, OUT unsigned long * order, OUT unsigned long * bom_len );

	ADDON_METHOD( SetEncoding )	( ADDON_REF(IObject) thiz, IN unsigned long enc, IN unsigned long order );

	ADDON_METHOD( NextChar )	( ADDON_REF(IObject) thiz, IN unsigned char * buff, IN unsigned long buff_size,
									OUT unsigned long * offset );

	ADDON_METHOD( PrevBreaker )	( ADDON_REF(IObject) thiz, IN unsigned char * buff, IN unsigned long buff_size,
									IN unsigned long buff_off, OUT unsigned long * brk_off, OUT unsigned long * skip_bytes );

	ADDON_METHOD( NextBreaker )	( ADDON_REF(IObject) thiz, IN unsigned char * buff, IN unsigned long buff_size,
									IN unsigned long buff_off, OUT unsigned long * brk_off, OUT unsigned long * skip_bytes );

	ADDON_METHOD( CharCount )	( ADDON_REF(IObject) thiz, IN unsigned char * buff, IN unsigned long buff_size,
									OUT unsigned long * cnt );

	ADDON_METHOD( EncodeUCS2 )	( ADDON_REF(IObject) thiz, IN unsigned short * dst_buff, IN unsigned long dst_size,
									IN unsigned char * src_buff, IN unsigned long src_size,
									OUT unsigned long * conv_len, OUT unsigned long * used_bytes );
};

/*************************************************************************
* DECLARATION
*************************************************************************/

#if defined(__cplusplus)
extern "C" {
#endif	// #if defined(__cplusplus)

ADDON_IMPORT ADDON_REF(IObject)	addon_create_encoding( void * reserved );

#if defined(__cplusplus)
}
#endif	// #if defined(__cplusplus)

/*************************************************************************
* MACRO
*************************************************************************/

#define IAddonEncoding_VTBL( p )							ADDON_GET_VTBL_(p, IAddonEncoding)
#define IAddonEncoding_CALL( p, a )							IAddonEncoding_VTBL(p)->a
#define IAddonEncoding_Guess( p, a, b, c, d, e )			IAddonEncoding_CALL( p, Guess )( p, a, b, c, d, e )
#define IAddonEncoding_SetEncoding( p, a, b )				IAddonEncoding_CALL( p, SetEncoding )( p, a, b )
#define IAddonEncoding_NextChar( p, a, b, c )				IAddonEncoding_CALL( p, NextChar )( p, a, b, c )
#define IAddonEncoding_PrevBreaker( p, a, b, c, d, e )		IAddonEncoding_CALL( p, PrevBreaker )( p, a, b, c, d, e )
#define IAddonEncoding_NextBreaker( p, a, b, c, d, e )		IAddonEncoding_CALL( p, NextBreaker )( p, a, b, c, d, e )
#define IAddonEncoding_CharCount( p, a, b, c )				IAddonEncoding_CALL( p, CharCount )( p, a, b, c )
#define IAddonEncoding_EncodeUCS2( p, a, b, c, d, e, f )	IAddonEncoding_CALL( p, EncodeUCS2 )( p, a, b, c, d, e, f )

#endif /* ADDON_ENCODING_H_ */
